/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * <p>Project: app2022 - FileInputStream3
 * <p>Powered by webrx On 2022-01-19 09:05:40
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class FileInputStream3 {
    public static void main(String[] args) {
        String f = "p.jpg";
        try (var fi = new FileInputStream(f); var fo = new FileOutputStream("m.jpg")) {

            //byte[] buf = new byte[fi.available()];
            //int s = fi.read(buf);
            //System.out.println(s);
            //System.out.println(buf);
            //System.out.println(buf.length);

            //int y = fi.read(buf);
            //System.out.println(y);
            //System.out.println(buf.length);

            //实现文件复制
            byte[] buf = new byte[1024 * 20];
            int len = -1;
            while ((len = fi.read(buf)) != -1) {
                fo.write(buf, 0, len);
            }

            //System.out.println(fi.available());//文字的字节个数
            //int t = 0;
            //fi.read() 在文件结束位置再读取就返回-1
            //while (fi.read() != -1) {
            //    ++t;
            //}
            //System.out.println(t);//循环次数
            //System.out.println(fi.available());

            //int i = fi.read();
            //System.out.println(i);
            //System.out.println(String.format("%02x", i));
            //System.out.println(String.format("%s", Integer.toBinaryString(i)));
            //i = fi.read();
            //System.out.println(i);
            //System.out.println(String.format("%02x", i));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
